﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using TomShane.Neoforce.Controls;

namespace XGameLibrary.Controls
{
    public class LeaderFacePlate : Control
    {
        Color selectedColor = Color.Red;
        Vector2 plateVec;
        Texture2D plate;
        Texture2D face;
        Texture2D battle;
        Vector2 vSNameVec;
        string vSName;
        Vector2 vLevelVec;
        int vLevel;
        Vector2 pkVec;
        bool isPk;
        double vLifeMax;
        double vLife;
        double vManaMax;
        double vMana;
        double vEnergyMax;
        double vEnergy;

        public LeaderFacePlate(Manager manager, Texture2D plate, Texture2D face, Texture2D battle, string vSName)
            : base(manager)
        {
            TabStop = false;
            HasFocus = false;
            Position = Vector2.Zero;
            vSName = "";
            vLevel = 0;
            isPk = true;
            vLifeMax = 0;
            vLife = 0;
            vManaMax = 0;
            vMana = 0;
            vEnergyMax = 0;
            vEnergy = 0;

            this.plate = plate;
            this.face = face;
            this.battle = battle;
            this.vSName = vSName;
        }

        public override void Update(GameTime gameTime)
        {
        }

        public void Update(int vLevel, bool isPk, double vLifeMax, double vLife, double vManaMax, double vMana, double vEnergyMax, double vEnergy)
        {            
            this.vLevel = vLevel;
            this.isPk = isPk;
            this.vLifeMax = vLifeMax;
            this.vLife = vLife;
            this.vManaMax = vManaMax;
            this.vMana = vMana;
            this.vEnergyMax = vEnergyMax;
            this.vEnergy = vEnergy;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
        }

        public void Draw(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(plate, new Rectangle((int)this.Position.X, (int)this.Position.Y, plate.Width, plate.Height), Color.White);
            spriteBatch.Draw(face, new Rectangle((int)this.Position.X+20, (int)this.Position.Y+13, face.Width, face.Height), Color.White);
            spriteBatch.Draw(battle, new Rectangle((int)this.Position.X + 62, (int)this.Position.Y + 65, battle.Width, battle.Height), Color.White);
            spriteBatch.DrawString(SpriteFont, this.vLevel.ToString(), this.Position +new Vector2(33,69), Color.White);
            Utility.DrawRectangle(graphicsDevice, spriteBatch, new Rectangle((int)this.Position.X + 89, (int)this.Position.Y + 22, (int)(155 * vLife / vLifeMax), 24), true);
            spriteBatch.DrawString(SpriteFont, vLife + "/" + vLifeMax, this.Position + new Vector2(100, 25), Color.White);
            Utility.DrawRectangle(graphicsDevice, spriteBatch, new Rectangle((int)this.Position.X + 89, (int)this.Position.Y + 48, (int)(110 * vMana / vManaMax), 15), true);
            spriteBatch.DrawString(SpriteFont, vMana + "/" + vManaMax, this.Position + new Vector2(100, 47), Color.White);
            Utility.DrawRectangle(graphicsDevice, spriteBatch, new Rectangle((int)this.Position.X + 89, (int)this.Position.Y + 68, (int)(100 * vEnergy / vEnergyMax), 10), true);
            spriteBatch.DrawString(SpriteFont, vEnergy + "/" + vEnergyMax, this.Position + new Vector2(100, 64), Color.White);
        }

        public override void HandleInput()
        {
            if (!HasFocus)
                return;

            if (InputHandler.KeyReleased(Keys.Enter))
                base.OnSelected(null);
        }

        public override void HandleMouse()
        {
            if (!HasFocus)
                return;

            if (InputHandler.MouseReleased(manager, InputHandler.MouseKey.LeftKey))
                base.OnSelected(null);
        }
    }
}
